#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        //子进程创建成功
        while(1)
        {
            printf("我是子进程, 我正在运行...Pid: %d\n", getpid());
            sleep(5);
            break;
        }
        exit(10);
    }
    else
    {
        //父进程
        int status = 0;
        printf("我是父进程：pid:%d, 我准备电脑等待子进程啦\n", getpid());
        pid_t ret = waitpid(id, &status, 0);
        if(ret > 0)
        {
            if(WIFEXITED(status))
            {
                printf("子进程是正常退出的，退出码: %d\n", WEXITSTATUS(status));
            }
        }
    }
    return 0;
}
